package test3_27.demo01;
/*
编号，姓名，年龄，工资，身份证号码，员工人数，员工工资总额
构造器1：设置编号，年龄，姓名；如果年龄小于18，抛出年龄低异常；如果年龄大于60抛出年龄高异常，如果姓名为null或为空字符串，抛出空异常。
构造器2：设置工资，设置身份证号码；如果工资低于600，抛出工资低异常。
 */

public class Employees{
    private int id;
    private String name;
    private int age;
    private double salary;
    private String idCardNum;
    private static int employeesNum;
    private static double employeesSalarySum;

    public Employees(int id, int age, String name, double salary, String idCardNum) {

        if (age<18){
            throw new AgeLowException("年龄小");
        }else if (age>60){
            throw new AgeHighException("年龄高");
        }
        if(name==null || name==""){
            throw new NullException("姓名为空");
        }

        if(salary<600){
            throw new SalaryLowException("工资过低");
        }

        this.id = id;
        this.age = age;
        this.name = name;
        this.salary = salary;
        this.idCardNum = idCardNum;
        employeesNum++;
        employeesSalarySum += salary;
    }


    /*
    增加工资 addSalary(double addSalary)，抛出工资高异常，当增加后的工资大于员工工资总额时，抛出此异常。
    减少工资 minusSalary(double minusSalary), 抛出工资低异常，当减少后的工资低于政府最低工资时，抛出工资低异常。
    显示员工工资总额方法：showTotalSalary(), 抛出空异常，当工资总额为0时，抛出此异常。
    显示员工人数：void showTotalEmployee（），抛出空异常。当员工人数为0时，抛出此异常。
     */

    public void addSalary(double addSalary){
        this.salary = salary+addSalary;
        if (this.salary>employeesSalarySum){
            throw new SalaryHighException("工资过高");
        }
        System.out.println("工资为：" + this.salary);
    }

    public void minusSalary(double minusSalary){
        this.salary = salary - minusSalary;
        if (this.salary<600){
            throw new SalaryLowException("工资过低");
        }
        System.out.println("工资为：" + this.salary);
    }

    public static void showTotalSalary(){
        if(employeesSalarySum == 0){
            throw new NullException("总工资为零");
        }
        System.out.println("总工资为：" + employeesSalarySum);
    }

    public static void showTotalEmployee(){
        if(employeesNum == 0){
            throw new NullException("总人数为零");
        }
        System.out.println("总人数为：" + employeesNum);
    }

}
